package com.fast.framework.core.service.impl;

import cn.hutool.core.util.ObjUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fast.framework.core.domain.User;
import com.fast.framework.core.mapper.UserMapper;
import com.fast.framework.core.request.UserRq;
import com.fast.framework.core.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 用户信息表 服务实现类
 * </p>
 *
 * @author lanyuankeji
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {

    @Resource
    private UserMapper userMapper;

    /**
     * 根据用户名称查找用户
     *
     * @param username 用户名
     * @return 用户对象
     */
    @Override
    public User selectUserByUserName(String username) {
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_name", username);
        return userMapper.selectOne(queryWrapper);
    }

    /**
     * 根据用户名查用户是否存在
     *
     * @param username 系统账号
     * @return 是否存在
     */
    @Override
    public boolean checkUserNameUnique(String username) {
        User user = selectUserByUserName(username);
        return !ObjUtil.isEmpty(user);
    }

    /**
     * 注册用户
     *
     * @param registerUser 待注册用户
     * @return 是否注册成功
     */
    @Override
    public boolean registerUser(User registerUser) {
        return userMapper.insert(registerUser) > 0;
    }

    /**
     * 获取用户列表
     *
     * @param user 匹配参数
     * @return 用户列表
     */
    @Override
    public List<User> selectUserList(UserRq user) {
        Integer pageNum = user.getPageNo();
        Integer pageSize = user.getPageSize();
        Page<User> page = new Page<>(pageNum, pageSize);
        List<User> list = userMapper.selectUserList(page, user);

        //处理数据



        return null;
    }
}
